
package instrumentation;


public class CoverageBranchTarget  {

	/** the ID of the targeted branch. */
	private int branchId;
	/** The distance to reach the target */
	private double distance;

	// HillClimbing number of attempt for each target
	private int attempt;
	public void setAttempt(int attempt){
		this.attempt=attempt;
	}
	public int getAttempt(){
		return this.attempt;
	}
	public CoverageBranchTarget(int branchId) {
		this.branchId = branchId;
		distance = Float.POSITIVE_INFINITY;
		attempt=0;
	}
	public void setDistance(double d) {
		if(this.branchId==-3)
			System.out.println("CoverageBranchTarget.setDistance: "+ distance +" , d=" +d);
			if(distance > d)
				distance = d;
	}
	public void setBranchId(int branchId) {
		this.branchId = branchId;
	}
	public int getBranchId() {
		return branchId;
	}
	

	/**
	 * Returns the quality: higher is better
	 */
	public float getQuality() {
		if(distance == -1) return 0;
		if(distance ==Float.POSITIVE_INFINITY) return 1;
		return (float) (1-(distance/(distance+1.0)));
	}

	@Override
	public String toString() {
		String predicate;
		predicate = "[branch:" + branchId + "] quality: " + getQuality();
		return predicate;
	}
}